/**
 * 
 */
package com.wskj.library.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

/**
 * @author 胡洋
 * @describe 
 * @Date 2018年3月22日下午6:15:10
 * @version 1.0
 */
@WebFilter(urlPatterns="/*",initParams= {@WebInitParam(name="encode",value="utf-8")})
public class CharacterFilter implements Filter {
     private String encode;
	
	@Override
	public void destroy() {		

	}

	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		
        req.setCharacterEncoding(encode);        
        resp.setCharacterEncoding(encode);        
        chain.doFilter(req, resp);
		
	}

	
	@Override
	public void init(FilterConfig config) throws ServletException {
		encode=config.getInitParameter("encode");

	}

}
